<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="../../common.jsp"></jsp:include>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function doSearch(){
		$('#grid').datagrid('load',{
            preHtml:$.trim($('#preHtmlTJ').val()),
            title:$.trim($('#titleTJ').val()),
	        }  
	     );  
	}
	function doAdd(){
        window.location.href="${pageContext.request.contextPath}/template/pageToTemplateXq.do";
	}
    function doView(){
        //选中一行进行编辑
        var rows = $("#grid").datagrid("getSelected");
        if (null == rows) {
            $.messager.alert('系统提示','请选择一条数据!','info');
            return ;
        }
        window.location.href="${pageContext.request.contextPath}/template/pageToTemplateXq.do?id="+rows.tid;
	}

	//删除
	function doDelete() {
		//选中一行进行编辑
		var rows = $("#grid").datagrid("getSelected");
		if (null == rows) {
			$.messager.alert('系统提示','请选择一条数据!','info');
			return ;
		}
		$.messager.confirm("确认删除","确定删除当前数据吗?",function(dd){
			if(dd){
				$.ajax({
					type:"POST",
					url: "${pageContext.request.contextPath}/ranks/delete.do",
					data:"ids="+rows.ranksid,
					success:function (result) {
						if(result == 1){
							$.messager.alert("系统提示","删除成功！");
						}else{
							$.messager.alert("系统提示","删除失败！");
						}
					}
				});
			} 
		});
	}



	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		$('#grid').datagrid({
			rownumbers: true,     //序号
			singleSelect:true,
			fit : true,
			pagination: true,     //开启分页  
	        pageSize: 10,         //分页大小  
	        pageNumber:1,         //第几页显示（默认第一页，可以省略）  
	        pageList: [10, 20, 30], //设置每页记录条数的列表
	        loadMsg: '正在拼命加载,请稍后...',
			striped: true,       //交替条纹
	        url: "${pageContext.request.contextPath}/template/selectTemplateList.do",
            columns:[[
                {field:'tid',width:180,hidden:'true',title:"编号",align:'center'},
                {field:'pre',width:180,hidden:'true',title:"预览图片",align:'center'},
                {field:'title',width:300,title:"预览提示",align:'center'},
                {field:'preHtml',width:300,title:"名称",align:'center'},
            ]],
            onDblClickRow:doDblClickRow,
        });
	});

	function doDblClickRow(rowIndex, rowData){
        window.location.href="${pageContext.request.contextPath}/template/pageToTemplateXq.do?id="+rowData.tid;

    }
</script>	


</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="center" border="false">
    	 <table id="grid"  data-options="toolbar:'#tb'">
		</table>

		<div id="tb" style="padding:5px;height:auto">
			 <div>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名称&nbsp;<input type="text" id="preHtmlTJ" size="20"/>
				&nbsp;预览提示&nbsp;<input type="text" id="titleTJ" size="20"/>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="doSearch()" plain="true">搜索</a>
			 </div>
			<div style="margin-bottom:5px">
				<a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="doAdd()">添加</a>
				<a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="doView()">编辑</a>
				<a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="doDelete()">删除</a>
			</div>
		</div>
	</div>
</body>
</html>	